package com.lmh.graphdisease.utils.ACKMPTree;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lmh
 * @desc AC关键词树上的节点
 * @date 2023/3/20
 */
public class Node {
    //当前节点的层级
    private int level;
    //当前节点的后子节点
    private Map<String,Node> subNodes;
    //当前节点匹配失败后的跳转节点
    private Node failNodeTo;
    //是否为终结节点
    private boolean terminal;

    /**
     *@author lmh
     *@date 2023/3/20
     *@desc 当前节点受否已包含指定key值的子节dian
     */
    public boolean containSubNode(String s){
        if(this.subNodes == null || this.subNodes.isEmpty()) return false;
        return subNodes.containsKey(s);
    }

    /**
     *@author lmh
     *@date 2023/3/20
     *@desc 获取指定key值的子节点
     */
    public Node getSubNode(String s){
        if(this.subNodes == null||this.subNodes.isEmpty()) return null;
        return subNodes.get(s);
    }

    /**
     *@author lmh
     *@date 2023/3/20
     *@desc 添加子节点
     */
    public void addSubNode(String s,Node node){
        if(this.subNodes == null){
            this.subNodes = new HashMap<>();
        }
        this.subNodes.put(s,node);
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public Map<String, Node> getSubNodes() {
        return subNodes;
    }

    public void setSubNodes(Map<String, Node> subNodes) {
        this.subNodes = subNodes;
    }

    public Node getFailNodeTo() {
        return failNodeTo;
    }

    public void setFailNodeTo(Node failNodeTo) {
        this.failNodeTo = failNodeTo;
    }

    public boolean isTerminal() {
        return terminal;
    }

    public void setTerminal(boolean terminal) {
        this.terminal = terminal;
    }
}
